package graphic.primitives.car;

import graphic.primitives.general.Circle;
import graphic.primitives.general.GraphicObject;
import graphic.primitives.general.IGraphicObject;
import graphic.window.MainWindow;
import java.awt.Color;
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Random;
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

/**
 *
 * @author Tomas Zima, Vit Terl
 */
public class Smoke extends GraphicObject implements IGraphicObject
{
	public Smoke(int x, int y)
	{
		super(x, y);
	}
	
	public Smoke()
	{
		super();
	}
	
	@Override
	public void redraw()
	{
		if (isEnabled())
		{
			//MainWindow.getInstance().setColor(Color.gray);
			Random r = new Random();

			if (lastUpdate > 10)
			{
				this.obj.clear();
				lastUpdate = 0;

				for (int i = 0; i < 30; i++)
				{
					int _x		= this.x;
					int _y		= this.y;
					int _r		= 10;
					
					_x -= Math.abs(r.nextInt() % 50);
					_y -= Math.abs(r.nextInt() % 70);
					_r += r.nextInt() % 5;

					obj.add(new Circle(_x, _y, _r));
				}
			}

			for (int i = 0; i < obj.size(); i++)
			{
				float c	= 0.7f;
				
				c -= ((float) r.nextInt(25)) / 100.0f;
				MainWindow.getInstance().setColor(new Color(c, c, c));				
				
				obj.get(i).redraw();
				lastUpdate++;
			}
			
			MainWindow.getInstance().setColor(Color.black);
		}
	}
	
	public void moveAtXAxis(int movement)
	{
		x += movement;
	}
	
	public void moveAtYAxis(int movement)
	{
		y += movement;
	}
	
	public void disable()
	{
		this.enabled = false;
	}
	
	public void enable()
	{
		this.enabled = true;
	}
	
	boolean isEnabled()
	{
		return enabled;
	}
	
	List<GraphicObject> obj = new LinkedList<GraphicObject>();
	int lastUpdate = 11;
	boolean enabled = false;
}
